#!/usr/bin/env python3
"""
课堂互动信号接收系统启动脚本
"""

import os
import subprocess
import sys
import time

def check_dependencies():
    """检查依赖项是否已安装"""
    try:
        import streamlit
        import bleak
        import numpy
        import pandas
        import matplotlib
        print("所有依赖项已安装，准备启动...")
        return True
    except ImportError as e:
        print(f"缺少依赖项: {str(e)}")
        install = input("是否自动安装依赖项？(y/n): ")
        if install.lower() == 'y':
            print("正在安装依赖项...")
            subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
            print("依赖项安装完成！")
            return True
        else:
            print("请手动安装依赖项: pip install -r requirements.txt")
            return False

def check_directories():
    """确保所需的目录存在"""
    if not os.path.exists('data'):
        print("创建数据目录...")
        os.makedirs('data', exist_ok=True)

def start_application():
    """启动Streamlit应用"""
    print("正在启动课堂互动信号接收系统...")
    subprocess.run([sys.executable, "-m", "streamlit", "run", "app.py", "--server.headless", "true"])

if __name__ == "__main__":
    print("=" * 50)
    print("        课堂互动信号接收系统")
    print("=" * 50)
    
    check_directories()
    
    if check_dependencies():
        start_application()
    else:
        print("程序启动失败，请检查依赖项。") 